<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('内部机构') }}</span>
    </div>
    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('机构全称')" prop="interFullName">
        <el-input
          v-model="queryParams.interFullName"
          :placeholder="$t('机构全称')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item :label="$t('机构简称')" prop="interName">
        <el-input
          v-model="queryParams.interName"
          :placeholder="$t('机构简称')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item :label="$t('组织形式')" prop="interType">
        <el-select v-model="queryParams.interType" :placeholder="$t('组织形式')" clearable>
          <el-option
            v-for="dict in interTypeOptions"
            :key="dict.dictValue"
            :label="$t(dict.dictLabel)"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t('搜索') }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t('重置') }}</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['base:internal:edit']"
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="addHandle"
        >{{ $t('新增') }}</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['base:internal:export']"
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="exportHandle"
        >{{ $t('导出') }}</el-button>
      </el-col>
    </el-row>
    <el-table v-loading="loading" :data="internalBaseList" border tooltip-effect="darkTable">
      <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50" fixed="left">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('机构全称')" align="center" min-width="200" prop="interFullName" fixed="left" show-overflow-tooltip>
        <template slot-scope="scope">
          <router-link
            target="_blank"
            :to="{path:'/fund/internal/internalBaseHome',query:{id:scope.row.id}}"
            class="link_a"
            @click.native="recorePath({ fromPath: $route.fullPath, path:'/fund/internal/internalBaseHome',query:{id:scope.row.id}})"
          >{{ scope.row.interFullName }}</router-link>
        </template>
      </el-table-column>
      <el-table-column :label="$t('机构简称')" align="center" min-width="200" prop="interName" show-overflow-tooltip />
      <el-table-column :label="$t('组织形式')" align="center" min-width="110" prop="interType" show-overflow-tooltip :formatter="interTypeFormat" />
      <el-table-column :label="$t('注册资本') + $t('金额单位')" min-width="110" align="center" show-overflow-tooltip prop="capitalRegistered">
        <template slot-scope="scope">
          <span class="money-text">{{ moneyFormat(scope.row.capitalRegistered, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('法定代表人')" align="center" min-width="150" prop="interRepresentative" show-overflow-tooltip />
      <el-table-column :label="$t('注册地-省')" align="center" min-width="90" prop="provinceRegisteredLabel" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ $t(scope.row.provinceRegisteredLabel) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('注册地-市')" align="center" min-width="90" prop="cityRegisteredLabel" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ $t(scope.row.cityRegisteredLabel) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('成立时间')" align="center" min-width="130" prop="interDate" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.interDate) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('操作')" align="center" min-width="150" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            v-hasPermi="['base:internal:edit']"
            size="small"
            type="text"
            icon="el-icon-edit"
            @click="updateHandle(scope.row)"
          >{{ $t('修改') }}</el-button>
          <el-button
            v-hasPermi="['base:internal:remove']"
            size="small"
            type="text"
            icon="el-icon-delete"
            @click="deleteHandle(scope.row)"
          >{{ $t('删除') }}</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改内部机构对话框 -->
    <el-dialog :title="$t(title)" :visible.sync="formOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
      <internalBaseForm ref="internalBaseForm" />
    </el-dialog>
  </div>
</template>

<script>
import { listInternalBase, delInternalBase } from '@/api/fund/internal/internalBase'
import internalBaseForm from './internalBaseForm.vue'
export default {
    components: {
        internalBaseForm
    },
  data() {
      return {
          // 遮罩层
          loading: true,
          // 总条数
          total: 0,
          // 内部机构表格数据
          internalBaseList: [],
          // 弹出层标题
          title: '内部机构',
          // 是否显示弹出层
          formOpen: false,
        // 组织形式字典
        interTypeOptions: [],

          // 查询参数
          queryParams: {
              interFullName: undefined,
              interName: undefined,
              interType: undefined,
              pageNum: 1,
              pageSize: 10
          },
          // 表单参数
          form: {},
          // 表单校验
          rules: {}
      }
  },
  created() {
      this.getList()
      this.getDicts('inter_type').then(response => {
          this.interTypeOptions = response.data
      })
  },
  methods: {
    /** 查询内部机构列表 */
    getList() {
        this.loading = true
        listInternalBase(this.queryParams).then(response => {
            this.internalBaseList = response.rows
            this.total = response.total
            this.loading = false
        })
    },
    // 组织形式字典翻译
    interTypeFormat(row) {
      return this.selectDictLabel(this.interTypeOptions, row.interType)
    },

    // 表单重置
    reset() {
        this.form = {
            id: undefined,

            interFullName: undefined,

            interName: undefined,

            interType: undefined,

            creditCode: undefined,

            capitalRegistered: undefined,

            interRepresentative: undefined,

            provinceRegistered: undefined,

            cityRegistered: undefined,

            interAddress: undefined,

            interDate: undefined,

            interLinkman: undefined,

            interPhone: undefined,

            interEmail: undefined,

            companyProfile: undefined,

            delFlag: undefined,

            createBy: undefined,

            createTime: undefined,

            updateBy: undefined,

            updateTime: undefined,

            tycId: undefined

        }
        this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
        this.queryParams.pageNum = 1
        this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
        this.resetForm('queryForm')
        this.queryHandle()
    },
    /** 新增按钮操作 */
    addHandle() {
        this.formOpen = true
        this.$nextTick(() => {
            this.$refs.internalBaseForm.init(null)
        })
    },
    /** 修改按钮操作 */
    updateHandle(row) {
        this.formOpen = true
        this.$nextTick(() => {
            // 调用form页面的 init 方法初始化数据
            this.$refs.internalBaseForm.init(row)
        })
    },
    /** 删除按钮操作 */
    deleteHandle(row) {
        this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
            confirmButtonText: this.$t('确定'),
            cancelButtonText: this.$t('取消'),
            type: 'warning'
        }).then(function() {
            return delInternalBase(row.id)
        }).then(() => {
            this.getList()
            this.msgSuccess(this.$t('删除成功'))
        }).catch(function() {
        })
    },
    /** 导出按钮操作 */
    exportHandle() {
      this.downLoadExcel('/base/internalBase/export', this.queryParams)
    }
  }
}
</script>
